//
//  MapInfoPopup.m
//  TowerDefence
//
//  Created by User on 6/26/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MapInfoPopup.h"

@implementation MapInfoPopup

-(id)initMapInfoPopupWith:(GameLayer *)_gameLayer mapDataFileName:(NSString *)_mapDataFileName {
    self = [super initPopupWith:_gameLayer];
    
    [self drawPopup];
    
    return self;
}

-(void)drawPopup {
    mainSprite = [[CCSprite alloc]initWithFile:IMAGE_POPUP_BACKGROUND];
    
    CCSprite *popupHeader = [CCSprite spriteWithFile:IMAGE_POPUP_HEADER_BACKGROUND];
    popupHeader.position = ccp(mainSprite.contentSize.width/2, mainSprite.contentSize.height);
    [mainSprite addChild:popupHeader];
    
    //header title
    CCLabelTTF *headerTitle = [CCLabelTTF labelWithString:@"APACHE" fontName:FONT_COMIC_BOOK fontSize:22];
    headerTitle.position = ccp(popupHeader.contentSize.width/2,popupHeader.contentSize.height/2 + 5);
    headerTitle.color = ccc3(0, 0, 0);
    [popupHeader addChild:headerTitle];
    
    //Map Thumbnail
    CCSprite *mapThumb = [CCSprite spriteWithFile:@"MapData/MapImage/map_1_thumbnail.bmp"];
    mapThumb.position = ccp(20 + mapThumb.contentSize.width/2, mainSprite.contentSize.height/2);
    [mainSprite addChild:mapThumb];
    
    //Map detail
    CCLabelTTF *mapDetail = [CCLabelTTF labelWithString:@"draw map detail string at here!!!" dimensions:CGSizeMake(220, mapThumb.contentSize.height) alignment:UITextAlignmentLeft fontName:FONT_MARKER_FELT fontSize:14];
    mapDetail.color = ccc3(45, 45, 45);
    mapDetail.anchorPoint = ccp(0, 1);
    mapDetail.position = ccp(mapThumb.position.x + mapThumb.contentSize.width/2 + 10, mapThumb.position.y + mapThumb.contentSize.height/2);
    [mainSprite addChild:mapDetail];
    
    //Draw money and start bonus
    CCSprite *moneyIcon = [CCSprite spriteWithFile:IMAGE_PLAYER_INFO_MONEY];
    moneyIcon.position = ccp(mapThumb.position.x + mapThumb.contentSize.width/2 + 10, mapThumb.position.y - mapThumb.contentSize.height/2);
    moneyIcon.anchorPoint = ccp(0, 0);
    moneyIcon.scale = 0.75f;
    [mainSprite addChild:moneyIcon];
    
    CCLabelTTF *moneyBonus = [CCLabelTTF labelWithString:@"200" fontName:FONT_MARKER_FELT fontSize:16];
    moneyBonus.anchorPoint = ccp(0, 0);
    moneyBonus.color = ccc3(255, 64, 64);
    moneyBonus.position = ccp(moneyIcon.position.x + moneyIcon.contentSize.width - 8,moneyIcon.position.y);
    [mainSprite addChild:moneyBonus];
    
    for(int i = 0; i < 5; i++) {
        CCSprite *starIcon = [CCSprite spriteWithFile:IMAGE_PLAYER_INFO_STAR];
        starIcon.position = ccp(moneyBonus.position.x + moneyBonus.contentSize.width + 20 + i*starIcon.contentSize.width/2, moneyBonus.position.y);
        starIcon.anchorPoint = ccp(0, 0);
        starIcon.scale = 0.5f;
        [mainSprite addChild:starIcon];
    }
    
    //Cancel and OK Button
    CCMenuItemImage *cancelButton = [CCMenuItemImage itemFromNormalImage:IMAGE_POPUP_BUTTON_BACKGROUND selectedImage:IMAGE_POPUP_BUTTON_SELECTED target:self selector:@selector(cancelButtonClick)];
    CCLabelTTF *cancelButtonLabel = [CCLabelTTF labelWithString:@"Cancel" fontName:FONT_COMIC_BOOK fontSize:26];
    cancelButtonLabel.color = ccc3(255, 255, 64);
    cancelButtonLabel.position = ccp(cancelButton.contentSize.width/2,cancelButton.contentSize.height/2);
    [cancelButton addChild:cancelButtonLabel];
    
    CCMenuItemImage *okButton = [CCMenuItemImage itemFromNormalImage:IMAGE_POPUP_GREEN_BUTTON_BACKGROUND selectedImage:IMAGE_POPUP_GREEN_BUTTON_SELECTED target:self selector:@selector(okButtonClick)];
    CCLabelTTF *okButtonLabel = [CCLabelTTF labelWithString:@"BATTLE" fontName:FONT_COMIC_BOOK fontSize:26];
    okButtonLabel.color = ccc3(255, 255, 64);
    okButtonLabel.position = ccp(okButton.contentSize.width/2,okButton.contentSize.height/2);
    [okButton addChild:okButtonLabel];
    
    CCMenu *buttonMenu = [CCMenu menuWithItems:cancelButton, okButton, nil];
    [buttonMenu alignItemsHorizontallyWithPadding:40.0f];
    buttonMenu.position = ccp(mainSprite.contentSize.width/2, 20 - cancelButton.contentSize.height/2);
    [mainSprite addChild:buttonMenu];
}

@end
